﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="../../js/scripts/boot.js" type="text/javascript"></script>
	<link href="../../js/scripts/miniui/themes/blue/skin.css" rel="stylesheet" type="text/css" />
	
	<style type="text/css">
		html, body {
			margin: 0;
			padding: 0;
			border: 0;
			width: 100%;
			height: 100%;
			overflow: hidden;
		}
	</style>
</head>
<body>

<form id="form1">
	<input name="id" class="mini-hidden" />
	<div style="padding-left:11px;padding-bottom:5px;">
		<table>
			<tr>
				<td align="center" width="10%">员工编码</td>
				<td width="23%">
					<input id="userNo" name="userNo" required="true" class="mini-textbox" style="width: 100%; display: inline-block;" />
				</td>
				<td align="center" width="10%">员工类型</td>
				<td width="23%">
					<input name="type" id="type" class="mini-combobox"
					 data='[{ "id": "1", "text": "员工" }, { "id": "2", "text": "项目经理" }]'
					 value="1" textField="text" valueField="id" style="width: 100%; display: inline-block;" />
				</td>
			</tr>
			<tr>
				<td align="center">员工姓名</td>
				<td><input id="nickName" name="nickName" class="mini-textbox" required="true" style="width: 100%; display: inline-block;" /></td>
				<td align="center">电子邮件</td>
				<td><input id="email" name="email" class="mini-textbox" required="true" style="width: 100%; display: inline-block;" />
				</td>
			</tr>
			<tr>
				<td align="center">登录名</td>
				<td><input id="name" name="name" class="mini-textbox" required="true" style="width: 100%; display: inline-block;"/></td>
				<td align="center" width="10%">性别</td>
				<td>
					<input name="sex" id="sex" class="mini-combobox"
					 data='[{ "id": "1", "text": "男" }, { "id": "2", "text": "女" }]'
					 value="1" textField="text" valueField="id" style="width: 100%; display: inline-block;" />
				</td>
			</tr>
			<tr>
				<td align="center">QQ号</td>
				<td><input id="qq" name="qq" class="mini-textbox" style="width: 100%; display: inline-block;" /></td>
				<td align="center" width="10%">家庭住址</td>
				<td>
					<input id="address" name="address" class="mini-textbox" style="width: 100%;"/>
				</td>
			</tr>
			<tr>
				<td align="center">出生日期</td>
				<td><input id="birthday" name="birthday" class="mini-datePicker" style="width: 100%; display: inline-block;" required = "true"/></td>
				<td align="center">手机号</td>
				<td><input id="telephone" name="telephone" class="mini-textbox" vtype="int" style="width: 100%; display: inline-block;" /></td>
			</tr>
			<c:if test="${sessionScope.userType == 3}">
			<tr>
				<td align="center">公司职务</td>
				<td><input id="job" name="job" class="mini-combobox" value="1" textField="text" valueField="id"
					 data='[{ "id": "1", "text": "工程师" }, { "id": "2", "text": "项目经理" }]' style="width: 100%; display: inline-block;" /></td>
				<td align="center" width="10%">所属部门</td>
				<td>
					<input id="dept" name="dept" class="mini-combobox" value="1" textField="text" valueField="id"
					 data='[{ "id": "1", "text": "研发部" }, { "id": "2", "text": "测试部" },{"id": "3", "text": "企划部"},{"id": "4", "text": "市场营销部"}]' style="width: 100%;"/>
				</td>
			</tr>
			</c:if>
		</table>
	</div>
    <div style="text-align:center;padding:10px;">               
           <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>       
           <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>       
    </div>
</form>

<script type="text/javascript">
	mini.parse();
	var userType = '<%= session.getAttribute("userType")%>';
	if(userType != 3){
		$("table tr:last").remove();
	}
	var type = mini.get("docType");
	var key = '';
    var form = new mini.Form("form1");
    function CloseWindow(action) {            
        if (action == "close" && form.isChanged()) {
            if (confirm("数据被修改了，是否先保存？")) {
                return false;
            }
        }
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();            
    }
    
    function onOk() {
        //提交表单数据
        var form = new mini.Form("#form1"); 
        
        form.validate();
        if (form.isValid() == false) return;
        
        var data = form.getData();      //获取表单多个控件的数据
       // var json = mini.encode(data);   //序列化成JSON

		if (!key) {
			$.ajax({
				url : "/document/user/addUser.do",
				type : "post",
				data : data,
				success : function(text) {
					CloseWindow({
						success : true,
						message : "保存成功"
					});
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
					CloseWindow();
				}
			});
		}else {
			$.ajax({
				url : "/document/user/editUser.do",
				type : "post",
				data : data,
				success : function(text) {
					CloseWindow({
						success : true,
						message : "修改成功"
					});
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
					CloseWindow();
				}
			});
		}
    }
	function onCancel(e) {
		CloseWindow("cancel");
	}

	function SetData(data) {
		if (data.action == "edit") {
			//跨页面传递的数据对象，克隆后才可以安全使用
			data = mini.clone(data);
			key = data.id;
			$.ajax({
				url : "/document/user/queryById.do?id=" + key,
				cache : false,
				success : function(text) {
					var o = mini.decode(text);
					form.setData(o);
					form.setChanged(false);
				}
			});
		}

	}
	function GetData() {
		var o = form.getData();
		return o;
	}
</script>

</body>
</html>